package gui;

import javax.swing.table.DefaultTableModel;

@SuppressWarnings("serial")
public abstract class JFrameTableBanco extends javax.swing.JFrame {

    // Atributos
    public static DefaultTableModel model;

    // Construtor
    @SuppressWarnings("static-access")
    public JFrameTableBanco(String nomeBorda) {
        this.initComponents(nomeBorda);
        this.model = (DefaultTableModel) jTableBanco.getModel();
    }

    // Métodos
    public void addColuna(String nome) {
        model.addColumn(nome);
    }

    protected void limpaBanco() {
        int totalRows = JFrameTableBanco.model.getRowCount();

        for (int i = 0; i < totalRows; i++) {
            JFrameTableBanco.model.removeRow(0);
        }
    }
    
    public void addLinha(Object[] linha) {
        model.addRow(linha);
    }

    private void initComponents(String nomeBorda) {

        jButtonNovo = new javax.swing.JButton();
        jButtonAlterar = new javax.swing.JButton();
        jButtonExcluir = new javax.swing.JButton();
        jButtonBuscar = new javax.swing.JButton();
        jPanelBorda = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableBanco = new javax.swing.JTable();

        jButtonNovo.setText("Novo");
        jButtonNovo.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNovoActionPerformed(evt);
            }
        });

        jButtonAlterar.setText("Alterar");
        jButtonAlterar.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAlterarActionPerformed(evt);
            }
        });

        jButtonExcluir.setText("Excluir");
        jButtonExcluir.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExcluirActionPerformed(evt);
            }
        });

        jButtonBuscar.setText("Buscar");
        jButtonBuscar.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarActionPerformed(evt);
            }
        });

        jPanelBorda.setBorder(javax.swing.BorderFactory.createTitledBorder(nomeBorda));

        jTableBanco.setModel(new DefaultTableModel());
        jScrollPane1.setViewportView(jTableBanco);

        javax.swing.GroupLayout jPanelBordaLayout = new javax.swing.GroupLayout(jPanelBorda);
        jPanelBorda.setLayout(jPanelBordaLayout);
        jPanelBordaLayout.setHorizontalGroup(
                jPanelBordaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanelBordaLayout.createSequentialGroup().addContainerGap().addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1031, Short.MAX_VALUE).addContainerGap()));
        jPanelBordaLayout.setVerticalGroup(
                jPanelBordaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanelBordaLayout.createSequentialGroup().addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 513, Short.MAX_VALUE).addContainerGap()));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap(29, Short.MAX_VALUE).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanelBorda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addGroup(layout.createSequentialGroup().addComponent(jButtonNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(33, 33, 33).addComponent(jButtonAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(33, 33, 33).addComponent(jButtonExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE).addGap(32, 32, 32).addComponent(jButtonBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))).addGap(27, 27, 27)));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(23, 23, 23).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jButtonNovo).addComponent(jButtonAlterar).addComponent(jButtonExcluir).addComponent(jButtonBuscar)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jPanelBorda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(31, Short.MAX_VALUE)));

        pack();
    }

    protected abstract void jButtonNovoActionPerformed(java.awt.event.ActionEvent evt);

    protected abstract void jButtonAlterarActionPerformed(java.awt.event.ActionEvent evt);

    protected abstract void jButtonExcluirActionPerformed(java.awt.event.ActionEvent evt);

    protected abstract void jButtonBuscarActionPerformed(java.awt.event.ActionEvent evt);
    // Variáveis
    private javax.swing.JButton jButtonAlterar;
    private javax.swing.JButton jButtonBuscar;
    private javax.swing.JButton jButtonExcluir;
    private javax.swing.JButton jButtonNovo;
    private javax.swing.JPanel jPanelBorda;
    private javax.swing.JScrollPane jScrollPane1;
    protected javax.swing.JTable jTableBanco;
}
